import React, { useState } from 'react'
import {message, Switch} from 'antd';
import './index.scss'
import Mimicryinput from '../../components/Mimicryinput';
import Loading from '../../components/Loading';
import { useStore } from '../../mobx'
import { useNavigate } from 'react-router-dom';
import { LockOutlined, SearchOutlined, UserOutlined } from '@ant-design/icons';


export default function Login() {
  const [loading,setloading]=useState(false)
  const {logincoking,userinformation}=useStore()
  const naiv=useNavigate()
  console.log('你好')
  const onFinish =async (value) => {
    setloading(true)
    const {data,error}=await userinformation.getinformation(value)  //先去数据库查找数据
    if(data.length!==0){
      
      await logincoking.getToken({
        mobile:value.username,
        code:'246810'   //接口的固定参数246810，还必须是string类型
      })
      setloading(false)
      message.success('登录成功', [1],()=>naiv('/'))
    }else{
      setloading(false)
      message.error('账号或密码错误',[2])
    }
    console.log(data,error,value);
  };

  return (
    <div className='login'>


      <Mimicryinput icon1={<UserOutlined /> } icon2={<LockOutlined/>} text='登录' register={false} onFinish={onFinish}/>
      {loading?<Loading/>:''}
      
        

    </div>
  )
}
